<!DOCTYPE html>
<html lang='zh-CN'>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />

    <title>会员分销表</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/materialdesignicons.min.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.min.css" rel="stylesheet">
    <link href="js/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
</head>
<body>
<div class="container-fluid p-t-15">

    <div class="row">
        <div class="col-md-12">
            <div class="card">
                <div class="card-header"><h4>会员分销</h4></div>
                <div id="myTabContent" class="tab-content">
                    <div class="tab-pane fade active in" id="home">

                        <form class="form-inline" method="post" id="searchForm">
                            <div class="form-group">
                                <label for="name" class="control-label">名称：</label>
                                <input type="text" class="form-control" id="name" name="name" required>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-info btn_query btn-round"  type="button" id="searchFormBtn" >查询</button>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-warning btn_query btn-round" type="button" id="editBtn">编辑</button>
                            </div>
                        </form>
                        <table id="hyfx_data"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!--  添加与编辑模态框 -->
    <div class="modal fade" id="addOrEditModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" >
        <div class="modal-dialog " role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true"></span></button>
                </div>
                <div class="modal-body">
                    <form id="addOrEditForm"  method="post">
                        <input type="hidden" name="id">
                        <div class="row">
                            <div class="col-xs-12">
                                <label for="names" class="control-label">名称：</label>
                                <input type="text" id="names" class="form-control"  name="name">
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-xs-12">
                                <label for="oneLevel" class="control-label">一级：</label>
                                <input type="text" id="oneLevel" class="form-control"  name="oneLevel" onkeyup="value=zhzs(this.value)">
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-xs-12">
                                <label for="twoLevel" class="control-label">二级：</label>
                                <input type="text" id="twoLevel" class="form-control"  name="twoLevel" onkeyup="value=zhzs(this.value)">
                            </div>
                        </div>
                    </form>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" id="saveFormBtn" class="btn btn-primary">保存</button>
                    </div>
                </div>
            </div>
        </div>
    </div>


<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/bootstrap-table/bootstrap-table.js"></script>
<script type="text/javascript" src="js/bootstrap-table/bootstrap-table-zh-CN.min.js"></script>
<script type="text/javascript" src="js/zero2one/zero2one.version.js"></script>
<script type="text/javascript" src="js/zero2one/zero2one.core.js"></script>
<script type="text/javascript" src="js/dropzone/min/dropzone.min.js"></script>
<script type="text/javascript" src="js/bootstrapvalidator/dist/js/bootstrapValidator.js"></script>
<!-- bootstrap表单验证插件 -->
<script type="text/javascript" src="js/bootstrap-validator-master/dist/validator.js"></script>
<!-- jquery-form表单提交插件 -->
<script type="text/javascript" src="js/jquery-form/jquery.form.js"></script>
<!-- bootstrap弹出框插件 -->
<script type="text/javascript" src="js/jquery.bootstrap.min.js"></script>
<!-- 表单填充插件 -->
<script type="text/javascript" src="js/jquery-form/jquery.formloader.js"></script>
<!-- ckeditor富文本插件 -->
<script src="js/ckeditor/ckeditor.js"></script>

<script type="text/javascript">

    //设置表头
    var columns = [
        {checkbox: true},
        {field: 'id',title: 'ID',visible:false},
        {field: 'name',title: '名称'},
        {field: 'oneLevel',title: '一级',formatter:function (value) {
             return value+" %";
            }},
        {field: 'twoLevel',title: '二级',formatter:function (value,row) {
                return value+" %";
            }},
        {field: 'type',title: '类型',visible: false},
        {field: 'open',title: '开关',formatter: function (value,row) {
             if (row.type==1){
                 if (value==0){
                     return "     <div class=\"form-group m-b-1\">\n" +
                         "    <div>驿站开关：</div>\n" +
                         "    <div>\n" +
                         "        <label class=\"lyear-switch switch-solid switch-success\">\n" +
                         "            <input type=\"checkbox\"  onclick=\'openEdit(checked,"+row.id+")\'>\n" +
                         "            <span></span>\n" +
                         "        </label>\n" +
                         "    </div>\n" +
                         "</div>";
                 }else {
                     return "     <div class=\"form-group m-b-1\">\n" +
                         "    <div>驿站开关：</div>\n" +
                         "    <div>\n" +
                         "        <label class=\"lyear-switch switch-solid switch-success\">\n" +
                         "            <input type=\"checkbox\" checked=\"checked\"  onclick=\'openEdit(checked,"+row.id+")\'>\n" +
                         "            <span></span>\n" +
                         "        </label>\n" +
                         "    </div>\n" +
                         "</div>";
                 }
             }else if (row.type==2){
                 if (value==0){
                     return "     <div class=\"form-group m-b-1\">\n" +
                         "    <div>商场开关：</div>\n" +
                         "    <div>\n" +
                         "        <label class=\"lyear-switch switch-solid switch-success\">\n" +
                         "            <input type=\"checkbox\"  onclick=\'openEdit(checked,"+row.id+")\'>\n" +
                         "            <span></span>\n" +
                         "        </label>\n" +
                         "    </div>\n" +
                         "</div>";
                 }else {
                     return "     <div class=\"form-group m-b-1\">\n" +
                         "    <div>商场开关：</div>\n" +
                         "    <div>\n" +
                         "        <label class=\"lyear-switch switch-solid switch-success\">\n" +
                         "            <input type=\"checkbox\" checked=\"\"  onclick=\'openEdit(checked,"+row.id+")\'>\n" +
                         "            <span></span>\n" +
                         "        </label>\n" +
                         "    </div>\n" +
                         "</div>";
                 }
             }else if (row.type==3){
                 if (value==0){
                     return "     <div class=\"form-group m-b-1\">\n" +
                         "    <div>同城开关：</div>\n" +
                         "    <div>\n" +
                         "        <label class=\"lyear-switch switch-solid switch-success\">\n" +
                         "            <input type=\"checkbox\"  onclick=\'openEdit(checked,"+row.id+")\'>\n" +
                         "            <span></span>\n" +
                         "        </label>\n" +
                         "    </div>\n" +
                         "</div>";
                 }else {
                     return "     <div class=\"form-group m-b-1\">\n" +
                         "    <div>同城开关：</div>\n" +
                         "    <div>\n" +
                         "        <label class=\"lyear-switch switch-solid switch-success\">\n" +
                         "            <input type=\"checkbox\" checked=\"\"  onclick=\'openEdit(checked,"+row.id+")\'>\n" +
                         "            <span></span>\n" +
                         "        </label>\n" +
                         "    </div>\n" +
                         "</div>";
                 }
             }else if (row.type== 4 || row.type == 5 || row.type == 6){
                 if (value==0){
                     return "     <div class=\"form-group m-b-1\">\n" +
                         "    <div>候鸟开关：</div>\n" +
                         "    <div>\n" +
                         "        <label class=\"lyear-switch switch-solid switch-success\">\n" +
                         "            <input type=\"checkbox\"  onclick=\'openEdit(checked,"+row.id+")\'>\n" +
                         "            <span></span>\n" +
                         "        </label>\n" +
                         "    </div>\n" +
                         "</div>";
                 }else {
                     return "     <div class=\"form-group m-b-1\">\n" +
                         "    <div>候鸟开关：</div>\n" +
                         "    <div>\n" +
                         "        <label class=\"lyear-switch switch-solid switch-success\">\n" +
                         "            <input type=\"checkbox\" checked=\"\"  onclick=\'openEdit(checked,"+row.id+")\'>\n" +
                         "            <span></span>\n" +
                         "        </label>\n" +
                         "    </div>\n" +
                         "</div>";
                 }
              }
            }},
    ];



    //进入主界面加载数据
    zero2one.datagrid("hyfx_data", "/remote/membershipDistribution/list",function (params) {
        return $.extend(zero2one.tableInitParam(params), zero2one.form2json("searchForm"));
    }, columns);

    //点击查询按钮重新加载页面数据
    $("#searchFormBtn").click(function () {
        $('#hyfx_data').bootstrapTable('refresh');
    });



    $('#addOrEditForm').bootstrapValidator({
        fields: {
            name: {validators: {notEmpty: {message: '名称不能为空'}}},
            oneLevel: {validators: {notEmpty: {message: '一级不能为空'}}},
            twoLevel: {validators: {notEmpty: {message: '二级不能为空'}}},
        }
    });

    //点击编辑按钮弹出模态框
    $("#editBtn").click(function () {
        //获取选中行的数据
        var datas = $('#hyfx_data').bootstrapTable('getSelections');
        //判断是否选中行数据，如果没有则提示
        if(datas.length == 1){
            //填充表单
            $("#addOrEditForm").formloader({data: datas[0]});
        }else{
            $.messager.alert("温馨提示", "请选择一条数据操作");
            return;
        }
        $("#addOrEditModal").modal("show");
    });



    //保存
    $("#saveFormBtn").click(function () {
        var bv = $('#addOrEditForm').data('bootstrapValidator');
        bv.validate();
        if (bv.isValid()) {
            //获取富文本编辑器的内容,设置到表单组件中
            zero2one.request("/remote/membershipDistribution/edit",$("#addOrEditForm").serialize(),function (data) {
                window.location.reload();
            });
        }
    });


    //开关编辑（按钮）
    function openEdit(open,ids){
        console.log(open);
        console.log(ids);
        $.post("/remote/membershipDistribution/openEdit", {"open": open,"ids": ids},function (data) {
            if (data.success) {
                    $.messager.alert("提示", "您已修改开关成功");
            } else {
                $.messager.alert("温馨提示", data.msg)
            }
        },"json");
    }


    //转化正整数
    function zhzs(value){
        //只可输入数字
        value = value.replace(/[^\d]/g,'');
        if(''!=value){
            value = parseInt(value);
        }
        return value;
    }

</script>
</div>
</body>
</html>
